COMPILER = gcc

INCDIRS  := mcunit

SRCFILES := main.c 

SRCDIRS  := mcunit 

DEFINES  :=
#OUTDIR   := objs
TARGET   := test_run

CFLAGS   := -fprofile-arcs -ftest-coverage -Wall -std=c99
LDFLAGS  := -fprofile-arcs -ftest-coverage -Wall -std=c99
LIBS     := -lcheck
DEBUG    := -g
OPT      :=

# compiler, linker and stuff 
CC  := gcc
AS  := as
AR  := ar
GDB := gdb
LD  := gcc
SZ  := size

############################
### Configure build here ###
############################

DEFS  := $(foreach _DEF, $(DEFINES), -D$(_DEF))
SRCS  := $(foreach _DIR, $(SRCDIRS), $(wildcard $(_DIR)/*.c)) $(SRCFILES)
OBJS  := $(SRCS:.c=.o)
GCDAS := $(SRCS:.c=.gcda)
GCNOS := $(SRCS:.c=.gcno)
GCOVS := $(SRCS:.c=.c.gcov)
INCS  := $(foreach _INC, $(INCDIRS), -I$(_INC))

COMPILER := $(CC) $(DEBUG) $(OPT) $(CFLAGS) $(DEFS) $(INCS)

bin: link

all: clean bin run

objects: $(OBJS)
	
%.o: %.c
  ifdef VERBOSE
	$(COMPILER) -o $(@) -c $(<)
  else
	@echo "  CC    $(<) $(@)"
	@$(COMPILER) -o $(@) -c $(<)
  endif
	

link: objects
  ifdef VERBOSE
	$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET)
  else
	@echo "  LD    $(TARGET)"
	@$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET)
  endif

run: link
	@echo "  RUN   $(TARGET)"
	@./$(TARGET)

clean:
	@echo Cleaning output files
	@rm -rf $(OBJS) $(TARGET) $(OUTDIR) *.
	@echo Cleaning coverage files
	@rm -rf $(GCDAS)
	@rm -rf $(GCNOS)
	@rm -rf $(GCOVS)
	
settings:
	@echo DEFS = $(DEFS)
	@echo SRCS = $(SRCS)
	@echo OBJS = $(OBJS)
	@echo INCS = $(INCS)
